/*
 * UpdateInventoryLine.java
 *
 * Created on April 5, 2007, 4:57 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.byu.isys413.actions;

import Data.*;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.http.*;

/**
 *
 * @author Danny Beutler
 */
public class UpdateInventoryLine implements edu.byu.isys413.web.Action{
    
    /** Creates a new instance of UpdateInventoryLine */
    public UpdateInventoryLine() {
    }
    
    public String process(HttpServletRequest request, HttpServletResponse response) throws Exception {
        HttpSession session = request.getSession();
        //get the Transline from the session
        TransactionLineBO transLine = (TransactionLineBO) session.getAttribute(request.getParameter("id"));
        //get the revenue Source  //Cast it as a sale
        SaleBO sale = (SaleBO) transLine.getRevenueSource();
        //Update the quantity
        int quantity=0;
        try {
            //Attach the Quantity to the sale
            quantity = Integer.valueOf(request.getParameter("quantity"));
        } catch (NumberFormatException ex) {
            request.setAttribute("parameterNames","Please enter a valid quantity!");
            return "buyStuff.jsp";
        }
        if(quantity<1){
            request.setAttribute("parameterNames","Please enter a quantity greater than 1");
            return "buyStuff.jsp";
        }
        sale.setQuantity(quantity);
        //Update the price
        sale.calculatePrice();
        
        return "buyStuff.jsp";
    }
}
